$(function(){

   setTimeout(() => {
       console.log($(".nav-header .title").length)
       $(".nav-header .title").click(function(){

           //"2019年08月".split("年")[0]
           // "2019年08月".split("年")[1].split("月")[0]
           let month = parseInt($(".month-title").text().split("年")[1].split("月")[0]) - 1
           $.ajax({
               url: 'http://10.112.70.1/manhour/manhour/list/month',
               type: 'POST',
               data: JSON.stringify({
                   endDay: new Date($(".month-title").text().split("年")[0], month + 1, 0).getTime() + "",
                   startDay: new Date($(".month-title").text().split("年")[0], month, 1).getTime() + ""
               }),
               // dataType: 'json',
               dataType: 'json',
               contentType: 'application/json;charset=UTF-8',
           }).then(data => {
               if(data.success) {
                   let r = {
                   }
                   let total = 0
                   data.result.map(item => {
                       Object.values(item.type).map(arr => {
                           arr.forEach(t => {
                               let jiraKey = t.jiraKey;
                               let manhourTypeId = t.manhourTypeId;
                               let attendanceTypeId = t.attendanceTypeId;
                               let hour = t.hour;
                               if(attendanceTypeId !== 15) {
                                   jiraKey = "其他"
                               } else {
                                   total += hour
                               }
                               if(r[jiraKey]) {
                                   r[jiraKey] += hour
                               } else {
                                   r[jiraKey] = hour
                               }
                           })
                       })
                   })
                   console.log("------------------------" + (month + 1)  + "月start-------------------------")
                   Object.keys(r).forEach(key => {
                       console.log(key, r[key] + '小时', parseFloat(r[key]/8).toFixed(2) + '天')
                   })
                   console.log("共计", total + '小时', parseFloat(total /8).toFixed(2) + '天')
                   console.log("------------------------" + (month + 1) + "月end-------------------------")
               }
           }, function(){

           });

       });
   },2000)
})
